"""分析相关的数据模式定义

定义了分析数据点、分析结果请求和响应的数据结构
用于处理脑波数据分析的输入输出格式
"""

from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel, Field


class AnalysisDataPoint(BaseModel):
    """分析数据点模型"""
    timestamp: float = Field(..., description="时间戳")
    state: str = Field(..., description="睡眠状态")
    confidence: float = Field(..., description="置信度", ge=0.0, le=1.0)
    delta: float = Field(..., description="Delta波比例", ge=0.0, le=1.0)
    theta: float = Field(..., description="Theta波比例", ge=0.0, le=1.0)
    alpha: float = Field(..., description="Alpha波比例", ge=0.0, le=1.0)
    beta: float = Field(..., description="Beta波比例", ge=0.0, le=1.0)
    gamma: float = Field(..., description="Gamma波比例", ge=0.0, le=1.0)


class AnalysisResultRequest(BaseModel):
    """分析结果请求模型"""
    session_id: str = Field(..., description="会话ID")
    user_id: str = Field(..., description="用户ID")
    room_id: Optional[str] = Field(None, description="房间ID")
    data: List[AnalysisDataPoint] = Field(..., description="分析数据点列表")
    
    class Config:
        json_encoders = {
            datetime: lambda v: v.isoformat()
        }


class AnalysisResultResponse(BaseModel):
    """分析结果响应模型"""
    success: bool = Field(..., description="操作是否成功")
    id: str = Field(..., description="会话ID")
    message: str = Field(..., description="响应消息")
    
    class Config:
        json_encoders = {
            datetime: lambda v: v.isoformat()
        }